<template>
	<view>
		<titleBar :titleText='"签到"' :pageForm='"setting"'></titleBar>
		<u-notice-bar :autoplay="true" :list="list"></u-notice-bar>
		<ss-calendar
		  :checks="checks"/>
		<view style="padding: 5px 5px;">
			<u-button type="primary"  :disabled="disabled" shape="square" @click="onSignInToday">签到</u-button>
		</view>
		<view class="xinrenhongbao">
			<image @click="goLottery" v-if="show_share" src="/static/img/my/choujiang.png"
				style="width: 160upx;height: 160upx;position: fixed;bottom: 160upx;right: 32upx;z-index: 99;">
			</image>
		</view>
	</view>
</template>

<script>
	import ssCalendar from '@/components/ss-calendar/ss-calendar.vue'
	import titleBar from '../../../components/customize/titlebar.vue'
	export default {
	  data() {
		return {
		  checks: [],
		  disabled:false,
		  show_share:true,
		  list: ['每日签到送积分哦~~~','记得每天来签到哦~~','积累积分可抽奖哦~~']
		}
	  },
	  components: {
		ssCalendar,
		titleBar
	  },
	  onShow(){
		  this.$u.api.user.signHistory().then((res) => {
		  	if (res.code != 200){
		  		this.$u.toast(res.msg);
		  	}
			for (var i = 0; i < res.data.length; i++) {
				this.checks.push(res.data[i]);
			}
			const { year, month, day } = this.getCurrentDate()
			if(this.checks.includes(`${year}-${month}-${day}`)){
				this.disabled=true;
			}
			var ss = `'${year}-${month}-${day}'`;
		  })
	  },
	  computed: {

	  },
	  methods: {
		onSignIn(payload) {
		  const { checked, year, month, day,isToday} = payload
		  !checked && this.checks.push(`${year}-${month}-${day}-${isToday}`)
		  console.log('onSignIn', payload)
		},
		onPrev(payload) {
		  console.log('onPrev', payload)
		},
		onNext(payload) {
		  console.log('onNext', payload)
		},
		onSignInToday() {
		  const { year, month, day } = this.getCurrentDate()
		  this.checks.push(`${year}-${month}-${day}`)
		  this.disabled=true;
		  this.$u.api.user.signIn().then((res) => {
				this.$u.toast(res.msg);
		  })
		},
		//获取当前时间
		getCurrentDate() {
		  let date = new Date()
		  let year = date.getFullYear()
		  let month = date.getMonth() + 1 + ""
		  debugger
		  if(month.length == 1){
			  month = '0' + month;
		  }
		  let day = date.getDate() + ""
		  if(day.length == 1){
		  	 day = '0' + day;
		  }
		  debugger
		  return {
			year,
			month,
			day
		  }
		},
		//抽奖
		goLottery(){
			uni.navigateTo({
				url: '/pages/my/lottery/lottery'
			})
		}
	  }
	}
</script>

<style>

	.xinrenhongbao image {
		animation: myfirst 1s infinite;
	}

	@keyframes myfirst {
		0% {
			transform: translate(0px, 0px);
		}

		50% {
			transform: translate(0px, -15px);
		}

		100% {
			transform: translate(0px, 0px);
		}
	}

</style>
